/**
 * 案例模块
 */

 define(function (require) {
	var $ = require('jquery');
	var base = require('base');
	var com = require('./common');

	if(localStorage.getItem("lang")){
		var Lang = localStorage.getItem("lang")
	}else{
		var Lang = "zh_CN"
	}

	// 中文/英文转换
	if(Lang != "zh_CN"){
		$('#banner_product_text').html("Product Center")
		$('#xntx').html("Performance Feature")
		$('#dctx').html("Features of sodium nickel batteries")
		$('#Product_Params').html("Product Params")

		$('#technical_params').html('<tr class="jscs_tr"><th>Technical params</th><th>value</th><th>unit</th></tr>')
		$('#basic_params').html('<tr class="jscs_tr"><th>Basic parameters</th><th>value</th><th>unit</th></tr>')

		$('#yyly').html("Application Areas")

	}


	changeSwiper = function(data){
		let htmlData2 = '<div class="swiper-container"><div class="swiper-wrapper">';
		data.forEach((item, index)=>{
			htmlData2 += '<div class="swiper-slide"><div class="item imgZoom">';		
			htmlData2 += '<div class="img_box"><a> <img src="'+item.icon+'"/>  </a></div>';
			htmlData2 += '<a> <div class="tit tit24 tit42">'+item.title+'</div>  </a>';
			htmlData2 += '</div></div>';
		})
		htmlData2 += '</div>';
		htmlData2 += '<div class="controls fix"><div class="swiper-pagination swiper-pagination-progressbar"><span class="swiper-pagination-progressbar-fill"></span></div></div></div>';
		
		$('#application_areas').html(htmlData2);

		var newsSwiper;
		function swiperRes() {
			if (base.getType() != 'Mobile') {
				if (!newsSwiper) {
					newsSwiper = new Swiper(".ipart4 .content .swiper-container", {
						autoplay: true,
						slidesPerView: 4,
						speed: 800,
						spaceBetween: '2.5%',
						observer: true,//修改swiper自己或子元素时，自动初始化swiper
						observeParents: true,//修改swiper的父元素时，自动初始化swiper						
						pagination: {
							el: '.ipart4 .content .swiper-container .swiper-pagination',
							type: 'progressbar'
						},
						navigation: {
							nextEl: '.ipart4 .content .swiper-container .swiper-button-next',
							prevEl: '.ipart4 .content .swiper-container .swiper-button-prev',
						}
					});
				}
			} else {
				if (newsSwiper) {
					newsSwiper.destroy(true, true);
					newsSwiper = null;
				}
			}
		}
		$(window).on('resize', swiperRes);
		swiperRes();
	}




	// 
	$.ajax(seajs.ajaxroot + "getProduct",{
		type:'post',		
		headers:{
			'locale-language':Lang
		},
		ajax:false,
		success:function(res){
            console.log("product:",res)
			let data = res.data;
			$('#main_img').html('<img src='+data.main_img+' alt="">')

			let performance_feature_list = '';
			data.performance_feature.forEach(item=>{
				performance_feature_list += '<div class="item_detail"><i></i>'+item.title+'</div>';
			})
			// $('#performance_feature').html(performance_feature_list)
			$('#feature_img').html('<img src='+data.feature_img+' alt="">')

			// 钠镍电池的特性
			let battery_feature_list = '';
			data.battery_feature.forEach(item=>{
				battery_feature_list += '<div class="ipart17_detail"><div>';
				battery_feature_list += '<div class="detail_item1"><img src="./cn/resources/web/images/dot.png" />'+item.title+'</div>';
				battery_feature_list += '<div class="detail_item2">'+item.description+'</div></div></div>';
				// battery_feature_list += '<div class="detail_item3">2、单体电池比能量135wh/kg，模组电池比能量120wh/kg</div>';				
			})
			$('#battery_feature').html(battery_feature_list)

			// 修改swiper 
			changeSwiper(data.application_areas)

			// 各种参数

			if(Lang != "zh_CN"){

			}



			let technical_params_list = '';
			data.technical_params.forEach(item=>{
				let value = item.value
				if(value == null) value = " ";
				let title = item.title
				if(title == null) title = " ";
				let unit = item.unit
				if(unit == null) unit = " ";
				technical_params_list += '<tr class="jscs_tr"><td>'+title+'</td><td>'+value+'</td><td>'+unit+'</td></tr>';				
			})
			$('#technical_params').append(technical_params_list)



			let basic_params_list = '';
			data.basic_params.forEach(item=>{
				let value = item.value
				if(value == null) value = " ";
				let title = item.title
				if(title == null) title = " ";
				let unit = item.unit
				if(unit == null) unit = " ";
				basic_params_list += '<tr class="jscs_tr"><td>'+title+'</td><td>'+value+'</td><td>'+unit+'</td></tr>';				
			})
			$('#basic_params').append(basic_params_list)

        }
    })

	/* 第四部分 start */
	// (function () {
	// 	var newsSwiper;
	// 	function swiperRes() {
	// 		if (base.getType() != 'Mobile') {
	// 			if (!newsSwiper) {
	// 				newsSwiper = new Swiper(".ipart4 .content .swiper-container", {
	// 					autoplay: true,
	// 					slidesPerView: 4,
	// 					speed: 800,
	// 					spaceBetween: '2.5%',
	// 					observer: true,//修改swiper自己或子元素时，自动初始化swiper
	// 					observeParents: true,//修改swiper的父元素时，自动初始化swiper						
	// 					pagination: {
	// 						el: '.ipart4 .content .swiper-container .swiper-pagination',
	// 						type: 'progressbar'
	// 					},
	// 					navigation: {
	// 						nextEl: '.ipart4 .content .swiper-container .swiper-button-next',
	// 						prevEl: '.ipart4 .content .swiper-container .swiper-button-prev',
	// 					}
	// 				});
	// 			}
	// 		} else {
	// 			if (newsSwiper) {
	// 				newsSwiper.destroy(true, true);
	// 				newsSwiper = null;
	// 			}
	// 		}
	// 	}
	// 	$(window).on('resize', swiperRes);
	// 	swiperRes();
	// })();
	/* 第四部分 end */


 })
